<template>
  <view class="container">
    <view class="header">
      <!-- <image src="/static/top.png" class="icon" /> -->
      <text class="title">近三个月市场行情</text>
    </view>

    <qiun-data-charts
      v-if="chartData && chartData.categories.length > 0"
      type="line"
      :opts="opts"
      :chartData="chartData"
      canvasId="marketChart"
      class="chart"
    />
  </view>
</template>

<script setup>
import { ref, onMounted } from 'vue';
const props = defineProps({
  chartData: {
    type: Object,
    default: () => ({
      categories: [],
      series: []
    })
  }
})

// 模拟数据
// const chartDatas = ref({
//   categories: ['3月前', '2月前', '1月前'],
//   series: [
//     {
//       name: '价格',
//       data: [1210, 1120, 1300]
//     }
//   ]
// });
console.log(Math.max(...props.chartData.series[0].data))
// 图表配置项
const opts = {
  color: ['#007AFF'],
  padding: [20, 10, 0, 15],
  enableScroll: false,
  legend: {
    show: false
  },
  xAxis: {
    disableGrid: true
  },
  yAxis: {
    gridType: 'dash',
    dashLength: 2,
    data: [{
      name: '',
      min: Math.min(...props.chartData.series[0].data) || 0,
      max: Math.max(...props.chartData.series[0].data) || 0,
      format: val => `${val}元`
    }]
  },
  extra: {
    line: {
      type: 'curve',
      width: 3,
      activeType: 'hollow',
      linearType: 'none',
      dataLabel: false,
      itemStyle: {
        borderWidth: 3
      }
    },
    tooltip: {
      showBox: true,
      format: (item) => `${item.category}：${item.data}元`
    },
    markLine: {}
  }
};

</script>

<style scoped>
.container {
  background-color: #fff;
  border-radius: 16px;
  box-shadow: 0 4px 12px rgba(0, 95, 227, 0.1);
  padding: 20px 0px;
}

.header {
  display: flex;
  align-items: center;
  margin-bottom: 12px;
}

.icon {
  width: 20px;
  height: 20px;
  margin-right: 6px;
  margin-left: 30px;
}

.title {
  font-size: 18px;
  font-weight: bold;
  color: #275ddb;
  padding-left: 20px;
}

.chart {
  width: 100%;
  height: 240px;
}
</style>
